package test10;

import java.io.*;
import java.util.Scanner;

public class Test10 {

    /**
     * 通过控制台输入一个字符串并将该字符串以字符为单位存储到文件中，将文件保存后的数据再读入到程序中进行显示
     *
     * @param args
     * @throws IOException
     */

    public static void main(String[] args) throws IOException {
        System.out.println("=========第十题===========================");
        test10();
    }


    public  static  void test10() throws IOException {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个字符串");
        String str = scan.next();

        System.out.println("保存到文件");
        PrintWriter pw = new PrintWriter(new File("test.txt"));
        pw.write(str);
        pw.close();

        System.out.println("读取");
        File file = new File("test.txt");
        if(file.exists()) {
            Reader in = new FileReader(file);
            char data[] = new char[1024];
            int len = in.read(data);
            System.out.println("读取的数据是："+new String(data, 0, len));
            in.close();
        }
    }
    }

